#coding:utf8
# GAE 上不支持


from kgdata import Kgdata

#保存为模版时不保存密码
def saveTemplateToGoogle(gemail, gpsw, gfilename, gwkshtname, templatename,\
                         smtpSver, logUser, senderMail, isSendMyself, \
                         toMails, macro, subject, mailContext):
    try:
        kgdata = Kgdata(gemail, gpsw)

        rtFileKey = kgdata.UploadSpreadsheet(u'null.ods', templatename)

        if rtFileKey:
            kgdata.curr_key = rtFileKey
            kgdata.set_wksht_id(u'Sheet1')
        else:
            return False
        
        if smtpSver.strip() == '': #防空数据
            smtpSver = u'Null'
        if logUser.strip() == '':
            logUser = u'Null'
        if senderMail.strip() == '':
            senderMail = u'Null'
        if toMails.strip() == '':
            toMails = u'Null'
        if subject.strip() == '':
            subject = u'Null'
        if mailContext.strip() == '':
            mailContext = u'Null'
            
        nCol = 1 #从一行一列开始写数据
        nRow = 1
        rt = True
        rt &= kgdata.CellsUpdateAction(nRow + 0, nCol, templatename)  #模版名
        rt &= kgdata.CellsUpdateAction(nRow + 1, nCol, smtpSver)      #
        rt &= kgdata.CellsUpdateAction(nRow + 2, nCol, logUser)       #
        rt &= kgdata.CellsUpdateAction(nRow + 3, nCol, senderMail)    #
        rt &= kgdata.CellsUpdateAction(nRow + 4, nCol, isSendMyself.__str__())  #
        rt &= kgdata.CellsUpdateAction(nRow + 5, nCol, toMails)       #
        rt &= kgdata.CellsUpdateAction(nRow + 6, nCol, macro)         #
        rt &= kgdata.CellsUpdateAction(nRow + 7, nCol, gemail)        #
        rt &= kgdata.CellsUpdateAction(nRow + 8, nCol, gfilename)     #
        rt &= kgdata.CellsUpdateAction(nRow + 9, nCol, gwkshtname)    #
        rt &= kgdata.CellsUpdateAction(nRow + 10, nCol, subject)      # 标题
        rt &= kgdata.CellsUpdateAction(nRow + 11, nCol, mailContext)  # 内容

        return rt

    except Exception, e:
        print e
        return False


if __name__ == '__main__':
    pass